/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-06-23 19:53:26
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-08-30 20:37:04
 * @FilePath: /server/workspace/src/base/thread.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#ifndef __YIZHI_THREAD_H
#define __YIZHI_THREAD_H
#include"noncapyable.h"
#include"functional"
#include"mutex.h"
#include <memory>
/// @brief 线程类封装
namespace Yizhi{
    class Thread:public noncopyable{
        public:
        typedef std::shared_ptr<Thread> ptr;
        typedef std::function<void()> CallbackType;
        public:
        Thread(CallbackType cb,std::string name);
        void join();
        ~Thread();


        int GetTid();
        void setDefaultName();

        static const std::string& getName(); 
        private:
        static void *run(void *rag);

        private:
        /// @brief 变量区
        CallbackType m_cb;//回调函数
        std::string m_name;//线程名
        uint64_t m_id;//线程id
        pthread_t m_thread;//线程
        Semaphore m_sem; //信号量
    };
}
#endif